<?php

namespace App\Models\Shop;

use App\Models\BaseModel;
use Illuminate\Http\Request;

class ShopAttributeModel extends BaseModel
{
    protected $table = 'shop_attribute';

    protected $primaryKey = 'id';

    public $dateFormat = 'U';

    protected $guarded = [];

    public function addOrEdit(Request $request)
    {
        $type_id = $request->post('goods_type');
        $title = $request->post('attr_title');
        $where['type_id'] = $data['type_id'] = $type_id;
        if(is_array($title)){
            foreach ($title as $value){
                $where['title'] = $data['title'] = $value;
                self::updateOrCreate($where,$data);
            }
            return true;
        }elseif($title){
            $where['title'] = $data['title'] = $title;
            self::updateOrCreate($where,$data);
        }
        return true;
    }
}
